﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

namespace YXShop.Web.admin.include
{
    public partial class storecenterlist_ajax : System.Web.UI.Page
    {
        YXShop.BLL.Store.StoreCenter bll = new YXShop.BLL.Store.StoreCenter();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Response.CacheControl = "no-cache";
                Response.Expires = 0;
                ProList.InnerHtml = AdminList();
            }
        }

        private string AdminList()
        {
            ChangeHope.WebPage.Table table = new ChangeHope.WebPage.Table();
            ChangeHope.DataBase.DataByPage dataPage;
            //如果当前用户是总部用户，那么能够选择所有销售中心。
            //如果是销售中心用户，只能选择该用户管理的销售中心。
            //如果是门店用户，只能选择该用户所管理的门店所在的销售中心
            YXShop.Model.Admin.AdminInfo admin = YXShop.Common.AdministrorManager.Get();
            if (admin.AdminType == 1)
            {
                dataPage = bll.GetList(" and iscenter=0");
            }
            else if (admin.AdminType == 2)
            {
                dataPage = bll.GetList(" and iscenter=0 and  adminid=" + admin.AdminId.ToString());

            }
            else
            {
                YXShop.BLL.Admin.Administrators adminBLL = new BLL.Admin.Administrators();
                List<YXShop.Model.Store.StoreCenter> centers = adminBLL.GetStoreCenterOfAdmin_Store(admin.AdminId);
                List<int> ids = new List<int>();
                foreach (YXShop.Model.Store.StoreCenter center in centers)
                {
                    ids.Add(center.Sid.Value);
                }
                dataPage = bll.GetList(" and iscenter=0 "+ChangeHope.Common.Util.GetWhereInClause(ids, "sid"));
                
            }
            table.AddHeadCol("","销售中心ID");
            table.AddHeadCol("","销售中心名称");
            table.AddRow();
            if(dataPage.DataReader!=null)
            {
                while(dataPage.DataReader.Read())
                {
                    table.AddCol(dataPage.DataReader["sid"].ToString());
                    table.AddCol("<span id=\"" + dataPage.DataReader["sid"].ToString() + "\" class=\"LableItem\"  onClick=\"SelectLable(this);sFiles('" + dataPage.DataReader["sid"].ToString() + "','" + dataPage.DataReader["storecentername"] + "');\">" + dataPage.DataReader["storecentername"] + "</span>");
                   // table.AddCol(dataPage.DataReader["UserId"].ToString());
                    //"<span id=\"" + dataPage.DataReader["UID"].ToString() + "\" class=\"LableItem\" ondblclick=\"ReturnValue();\" onClick=\"SelectLable(this);sFiles('" + dataPage.DataReader["UID"].ToString() + "','" + dataPage.DataReader["UserId"] + "');\">" + dataPage.DataReader["UserId"] + "</span>";
                    table.AddRow();
                }
            }
            string view = table.GetTable() + dataPage.PageToolBar;
            dataPage.Dispose();
            dataPage = null;
            return view;
        }
    }
}
